<?php
FLEA::loadClass('FLEA_Db_TableDataGateway');

class Model_UserInfo extends FLEA_Db_TableDataGateway
{
	var $tableName = 'sysusers';
	var $primaryKey = 'user_id';
	
	var $hasOne = array(
		array('tableClass' => 'Model_DeclarePerson',
			'foreignKey' => 'user_id',
			'mappingName' => 'declareperson',
		),
		array('tableClass' => 'Model_DeclareCompany',
			'foreignKey' => 'user_id',
			'mappingName' => 'declarecompany',
		),        
    );
    
    function analysisUserInfo($db,$userID){
    	$list = $db -> find($userID);
    	$result = array(
    		'username' => $list['username'],
    		'nickname' => $list['declareperson']['name'],
    		'email' => $list['email'],
    		'createdDate' => date('Y-m-d', $list['created']),
    		'updatedDate' => date('Y-m-d',$list['updated']),
    		'lastLogin' => date('Y-m-d',$list['lastLogin']),
    		'loginCount' => $list['loginCount'],
    		'lastLoginIp' => $list['lastLoginIp'],
    		'cellphone' => $list['declareperson']['cellphone'],
    		'validTime' => $list['validTime'],
    		'declareperson_id' => $list['declareperson']['id'],
    	);

    	return $result;
    }
}
?>